package 算法.leetcode.linked.list;

import org.junit.Test;

/**
 * @author lchenglong
 * @date 2020/12/14
 */
public class DeleteDuplicates extends LinkListBase{


    @Test
    public void test() {
        int[] arr = new int[]{1,1,1,2,2,2,2,3,3,4,4,5,5,5,5,5,5,};
        ListNode head = createTestData(arr);
        ListNode listNode = deleteDuplicates(head);
        for (;listNode!=null;listNode=listNode.next) {
            System.out.print(listNode.val);
            System.out.print("-->");
        }

    }


    public ListNode deleteDuplicates(ListNode head) {
        ListNode ptr = head;
        while (ptr!=null &&ptr.next!=null) {
            int val = ptr.val;
            int nextVal = ptr.next.val;
            if (val == nextVal) {
                ptr.next = ptr.next.next;
            } else {
                ptr = ptr.next;
            }
        }
        return head;
    }


}
